<?php
/**
 * Created by PhpStorm.
 * User: tom_xia
 * Date: 2017/11/13
 * Time: 19:17
 * 返回给客户端的
 */

namespace app\cls\tom;


class Response
{
    public $code = 0;
    public $msg = "";
    public $count = null;
    public $data = null;

    public static function output($code, $msg, $data = null, $count = null)
    {
        @ob_clean();
        /*        if(PRODUCT_MODE == "production"){
                    $msg = substr($msg,0,strpos($msg,"==>"));
                }*/
        $obj = new Response($code, $msg, $data, $count);
        echo json_encode($obj, JSON_UNESCAPED_UNICODE);
        exit;
    }

    public static function outputSelf(Response $re)
    {
        @ob_clean();
        echo json_encode($re, JSON_UNESCAPED_UNICODE);
        exit;
    }

    public static function badRequest()
    {
        header("HTTP/1.1 400 bad request");
        exit;
    }

    public function __construct($code, $msg, $data = null, $count = null)
    {
        $this->code = $code;
        $this->msg = $msg;
        $this->data = $data;
        $this->count = $count;
    }

    public function setCount($count)
    {
        $this->count = $count;

    }

    public function setCode($code)
    {
        $this->code = $code;
    }

    public function setMsg($msg)
    {
        $this->msg = $msg;
    }

    public function setData($data)
    {
        $this->data = $data;
    }
}